package com.xiaofu.live.user.provider;

import com.xiaofu.live.user.constants.UserTagsEnum;
import com.xiaofu.live.user.dto.UserDTO;
import com.xiaofu.live.user.provider.service.IUserService;
import com.xiaofu.live.user.provider.service.IUserTagService;
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;

/**
 * 用户中台dubbo服务提供者
 */

@SpringBootApplication
@EnableDubbo
@EnableDiscoveryClient
public class UserProviderApplication implements CommandLineRunner {

    public static void main(String[] args) {
        SpringApplication springApplication = new SpringApplication(UserProviderApplication.class);

        springApplication.setWebApplicationType(WebApplicationType.NONE);

        springApplication.run(args);

    }

    @Autowired
    private IUserTagService userTagService;

    @Autowired
    private IUserService userService;

    @Override
    public void run(String... args) throws Exception {
        /*long userId = 1001L;
        System.out.println(userTagService.setTag(userId, UserTagsEnum.IS_RICH));
        System.out.println("当前用户是否拥有 is_rich标签: "+ userTagService.containTag(userId,UserTagsEnum.IS_RICH));
        System.out.println(userTagService.setTag(userId, UserTagsEnum.IS_VIP));
        System.out.println("当前用户是否拥有 is_vip标签: "+ userTagService.containTag(userId,UserTagsEnum.IS_VIP));
        System.out.println(userTagService.setTag(userId, UserTagsEnum.IS_OLD_USER));
        System.out.println("当前用户是否拥有 is_old_user标签: "+ userTagService.containTag(userId,UserTagsEnum.IS_OLD_USER));
        System.out.println("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
        System.out.println(userTagService.cancelTag(userId, UserTagsEnum.IS_RICH));
        System.out.println("当前用户是否拥有 is_rich标签: "+ userTagService.containTag(userId,UserTagsEnum.IS_RICH));
        System.out.println(userTagService.cancelTag(userId, UserTagsEnum.IS_VIP));
        System.out.println("当前用户是否拥有 is_vip标签: "+ userTagService.containTag(userId,UserTagsEnum.IS_VIP));
        System.out.println(userTagService.cancelTag(userId, UserTagsEnum.IS_OLD_USER));
        System.out.println("当前用户是否拥有 is_old_user标签: "+ userTagService.containTag(userId,UserTagsEnum.IS_OLD_USER));
*/

        Long userId = 1004L;
        UserDTO userDTO = userService.getByUserId(userId);
        userDTO.setNickName("test-nick-name");
        userService.updateUserInfo(userDTO);

        System.out.println(userTagService.containTag(userId, UserTagsEnum.IS_OLD_USER));
        System.out.println(userTagService.setTag(userId,UserTagsEnum.IS_OLD_USER));
        System.out.println(userTagService.containTag(userId,UserTagsEnum.IS_OLD_USER));

        System.out.println(userTagService.cancelTag(userId,UserTagsEnum.IS_OLD_USER));
        System.out.println(userTagService.containTag(userId,UserTagsEnum.IS_OLD_USER));
    }
}
